<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div id="app">
    <cpn :number1='num1' :number2='num2' @num1change='num1Change' @num2change='num2Change'></cpn>
  </div>
  <template id="cpn">
    <div>
      <h3>props{{number1}}</h3>
      <p>data{{dnumber1}}</p>
      <input type="text" v-model='dnumber1'>
      <h3>props{{number2}}</h3>
      <p>data{{dnumber2}}</p>
      <input type="text" v-model='dnumber2'>
    </div>
  </template>
  <script src="../../vue.js"></script>
  <script>
    new Vue({
      el: '#app',
      data: {
        num1: 10,
        num2: 20
      },
      methods: {
        num1Change(value) {
          this.num1 = value;
        },
        num2Change(value) {
          this.num2 = value;
        }
      },
      components: {
        cpn: {
          template: '#cpn',
          props: {
            number1: Number,
            number2: Number
          },
          data() {
            return {
              dnumber1: this.number1,
              dnumber2: this.number2
            }
          },
          watch: {
            //TODO 这就是监听器吗 阿里阿里
            dnumber1(newValue) {
              // this.dnumber1 = parseInt(event.target.value)
              this.$emit('num1change', newValue)
              // 同时修改dnumber2数据
              this.dnumber2 = newValue * 100
              // this.$emit('num2change', this.dnumber2)
            },
            dnumber2(newValue) {
              // this.dnumber2 = parseInt(event.target.value)
              this.$emit('num2change', newValue)
              // 同时修改dnumber1数据
              this.dnumber1 = newValue / 100
              // this.$emit('num1change', this.dnumber1)
            },
          }
        }
      }
    })
  </script>
</body>

</html>